package cn.edu.cdu.argorithm.impl;

import cn.edu.cdu.argorithm.IPlusOne;

public class PlusOneSolutions implements IPlusOne {
    @Override
    public int[] plusOne(int[] digits) {
        int n = digits.length;
        for (int i =  n - 1; i > -1; --i) {
            digits[i] = (digits[i] + 1) % 10;
            if(digits[i] != 0) {
                return digits;
            }
        }
        int[] ret = new int[n + 1];
        ret[0] = 1;
        return ret;
    }
}
